package com.crl.gen.dao;

import com.crl.dao.BaseDao;
import com.crl.gen.model.GenField;
import com.crl.gen.vo.GenFieldSearchVO;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description:
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/22 23:02
 */
@Repository
public class GenFieldDao2 extends BaseDao<GenField, GenFieldSearchVO> {

    /**
     * 新增
     *
     * @param genField
     * @return
     */
    public int add(GenField genField) {
        String sql = "INSERT INTO td_gen_field(id,table_id,fieldcode,fieldname,description,type,length,point,is_list_field,list_width,list_align,input_length,is_search_field,is_blank,display_order) " +
                "VALUES(seq_td_gen_field.nextVal,:tableId,:fieldcode,:fieldname,:description,:type,:length,:point,:isListField,:listWidth,:listAlign,:inputLength,:isSearchField,:isBlank,:displayOrder)";
        return insert(sql, genField);
    }


    /**
     * 修改
     *
     * @param genField
     * @return
     */
    public int update(GenField genField) {
        String sql = "UPDATE td_gen_field SET fieldcode=:fieldcode,fieldname=:fieldname,description=:description,type=:type,length=:length," +
                "point=:point,input_length=:inputLength,is_list_field=:isListField,list_width=:listWidth,list_align=:listAlign,is_search_field=:isSearchField,is_blank=:isBlank,display_order=:displayOrder WHERE id=:id";
        return update(sql, genField);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    public int delete(int id) {
        String sql = "DELETE FROM td_gen_field WHERE id=?";
        return delete(sql, id);
    }

    /**
     * 按tableId删除
     * @param tableId
     * @return
     */
    public int deleteByTableId(int tableId) {
        String sql = "DELETE FROM td_gen_field WHERE table_id=?";
        return delete(sql, tableId);
    }

    /**
     * 列表
     *
     * @return
     */
    public List<GenField> list(int tableId) {
        String sql = "SELECT id,table_id,fieldcode,fieldname,description,type,length,point,input_length,is_list_field,is_search_field,is_blank,display_order,list_width,list_align FROM td_gen_field WHERE 1=1 and table_id=? ";
        sql += " ORDER BY display_order ASC";
        return list(sql,tableId);
    }

    /**
     * 获取单个
     *
     * @param id
     * @return
     */
    public GenField get(int id) {
        String sql = "SELECT id,table_id,fieldcode,fieldname,description,type,length,point,input_length,is_list_field,is_search_field,is_blank,display_order,list_width,list_align FROM td_gen_field WHERE id=?";
        return get(sql, id);
    }

}
